package com.wngbms;

import lombok.extern.slf4j.Slf4j;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func0;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;

@Slf4j
public class LiftDemo {

    public static void main(String[] args) {
        final Observable<String> observable = Observable.just("windows");

        final Observable<String> lift = observable.lift(new Observable.Operator<String, String>() {
            @Override
            public Subscriber<? super String> call(Subscriber<? super String> subscriber) {
                return new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        log.info("1 onCompleted");
                        subscriber.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(String s) {
                        log.info("1 onNext {}", s);
                        subscriber.onNext(s);
                        subscriber.onNext(s);
                    }
                };
            }
        });

        Observable<String> lift1 = lift.lift(new Observable.Operator<String, String>() {
            @Override
            public Subscriber<? super String> call(Subscriber<? super String> subscriber) {
                return new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        log.info("2 onCompleted");
                        subscriber.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(String s) {
                        log.info("2 onNext {}", s);
                        subscriber.onNext(s);
//                        subscriber.onNext(s);
                    }
                };
            }
        });

        Observable<String> lift2 = lift1.lift(new Observable.Operator<String, String>() {
            @Override
            public Subscriber<? super String> call(Subscriber<? super String> subscriber) {
                return new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        log.info("3 onCompleted");
                        subscriber.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(String s) {
                        log.info("3 onNext {}", s);
                        subscriber.onNext(s);
//                        subscriber.onNext(s);
                    }
                };
            }
        });

        lift2.subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                log.info("subscribe {}", s);
            }
        });

    }

}

